package com.smforj.ssm.mina.message;

import java.io.Serializable;
import java.nio.charset.Charset;

import com.smforj.ssm.mina.codec.MsgUtils;
import com.smforj.ssm.mina.test.TestClient;

/**
 * 消息头
 * @author ghj
 *   
 */
public class MessageHeader implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1088974227374959387L;
	public static final int [] LENARRAY = new int[]{12,4,8,20,20,4,4,16,4,4,20,4,4,4,52};
	//标记标记 
	private String flag;
	//版本
	private int version;
	//设备类型
	private String deviceType;
	//站点父节点编号
	private String siteParent;
	//站点子节点编号
	private String siteChild;
	//设备通道类型
	private String deviceChannelType;
	//设备编号
	private int deviceNo;
	//设备IP:
	private String deviceIp;
	//比对总结果（警告类型）
	private int warnType;
	//人工处理
	private int manual;
	//采集时间2014/10/17(空格)14:17:36
	private String date;
	//消息体长度
	private int msgLength;
	//人脸比对结果
	private int faceiRes;
	//指纹比对结果
	private int handiRes;
	//预留
	private String reserve;
	
	
	public String getFlag() { 
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	public int getVersion() {
		return version;
	}
	public void setVersion(int version) {
		this.version = version;
	}
	public String getDeviceType() { 
		return deviceType;
	}
	public void setDeviceType(String deviceType) {
		this.deviceType = deviceType;
	}
	public String getSiteParent() {
		return siteParent;
	}
	public void setSiteParent(String siteParent) {
		this.siteParent = siteParent;
	}
	public String getSiteChild() {
		return siteChild;
	}
	public void setSiteChild(String siteChild) {
		this.siteChild = siteChild;
	}
	public String getDeviceChannelType() {
		return deviceChannelType;
	}
	public void setDeviceChannelType(String deviceChannelType) {
		this.deviceChannelType = deviceChannelType;
	}
	public int getDeviceNo() {
		return deviceNo;
	}
	public void setDeviceNo(int deviceNo) {
		this.deviceNo = deviceNo;
	}
	public String getDeviceIp() {
		return deviceIp;
	}
	public void setDeviceIp(String deviceIp) {
		this.deviceIp = deviceIp;
	}
	public int getWarnType() {
		return warnType;
	}
	public void setWarnType(int warnType) {
		this.warnType = warnType;
	}
	public int getManual() {
		return manual;
	}
	public void setManual(int manual) {
		this.manual = manual;
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public int getMsgLength() {
		return msgLength;
	}
	public void setMsgLength(int msgLength) {
		this.msgLength = msgLength;
	}
	public String getReserve() {
		return reserve;
	}
	public void setReserve(String reserve) {
		this.reserve = reserve;
	}
	public int getFaceiRes() {
		return faceiRes;
	}
	public void setFaceiRes(int faceiRes) {
		this.faceiRes = faceiRes;
	}
	public int getHandiRes() {
		return handiRes;
	}
	public void setHandiRes(int handiRes) {
		this.handiRes = handiRes;
	} 
	
	/***
	 * 获取byte[] 数组
	 * @return
	 */
	public byte[] getBytes()
	{
		return MessageModel.ObjectToByte(this); 
	}
	
	public int getHeaderLength()
	{
		return 180;
	}
	
	public void print() {
		System.out.println("-------MessageHeader Print Start----------");
		System.out.println("标记标记: "+flag);
		System.out.println("版本: "+version);
		System.out.println("设备类型: "+ deviceType);
		System.out.println("站点父节点编号: "+ siteParent);
		System.out.println("站点子节点编号: "+ siteChild);
		System.out.println("设备通道类型: "+ deviceChannelType);
		System.out.println("设备编号: "+ deviceNo);
		System.out.println("设备IP: "+ deviceIp);
		System.out.println("比对总结果（警告类型）: "+ warnType);
		System.out.println("人工处理: "+ manual);
		System.out.println("采集时间2014/10/17(空格)14:17:36: "+ date);
		System.out.println("消息体长度: "+ msgLength);
		System.out.println("人脸比对结果: "+ faceiRes);
		System.out.println("指纹比对结果: "+ handiRes);
		System.out.println("预留: "+ reserve);
		System.out.println("-------MessageHeader Print End----------");
	}
	
	@SuppressWarnings("unused")
	public static void main(String[] arg0)
	{  
		Integer iii = 345435435;
		String str2 = Integer.toBinaryString(iii);
		byte[] bbbbb = str2.getBytes();
		byte[] data = TestClient.CreateDataHeader(); 
		byte[] bl = new byte[4];
		System.arraycopy(data, 116, bl, 0, 4);
		System.out.println(MsgUtils.bytesToInt(bl));
		
		String str = new String(data);
		
		byte[] b = str.getBytes(Charset.forName("UTF-8"));
		bl = new byte[4];
		System.arraycopy(b, 116, bl, 0, 4);
		System.out.println(MsgUtils.bytesToInt(bl));
		String str1 = new String(b,Charset.forName("UTF-8"));
		
		
		
		System.out.println(str1);
	}
}
